package com.wlyuan.open.constants;

import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 打包方式
 *
 * @author lijing
 */
@Getter
public enum PackageMode {

    BULK("散箱", 1),
    TRAY("托盘或木箱", 2),
    ANOMALOUS("托盘、木箱或不规则形状", 3),
    ;

    private final String name;
    private final Integer value;

    PackageMode(String name, Integer value) {
        this.value = value;
        this.name = name;
    }

    private static final Map<Integer, PackageMode> MAP = Arrays.asList(PackageMode.values()).stream().collect(Collectors.toMap(PackageMode::getValue, Function.identity()));

    public static PackageMode fromValue(Integer value) {
        return Optional.ofNullable(value).map(a -> Optional.ofNullable(MAP.get(a)).orElse(BULK)).orElse(BULK);
    }

}
